<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use App\Repository\Models\Actions;

/**
 * Class Menu.
 *
 * @package namespace App\Repository\Models;
 */
class Menu extends Model implements Transformable
{
    use TransformableTrait;

/*
* @var array
*/
    protected static $index = [
        'id',
        'name',
        'route',
        'icon',
        'parent_id',
    ];

    /**
     * [$guarded description]
     *
     * @var string
     */
    protected static $sort = 'desc';

    /**
     * [$guarded description]
     *
     * @var array
     */
    protected $guarded = [];
    
    protected $hidden = ['id'];

    protected $appends = ['menu_id'];
    
    protected $fillable = [ 'name', 'parent_id', 'description', 'route','icon','sort','apiroute','hide' ];
   
    protected $table = "menus";

    public function getMenuIdAttribute()
    {
        return $this->id;
    }


    public function actions()
    {
        return $this->hasMany(Action::class, 'menu_id', 'menu_id');
    }

    public function menuAction()
    {
        return $this->hasMany(Action::class,'menu_id','id');
    }

    public function menuPermission()
    {
        return $this->hasOne(MenuPermission::class,'menu_id','id');
    }

}
